home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.object,comp.lang.c++,comp.lang.java
- Path: newsfeed.acns.nwu.edu!ftpbox!mothost!schbbs!news
- From: shang@corp.mot.com (David L. Shang)
- Subject: Re: Java: What's the Big Deal? (GC)
- Reply-To: shang@corp.mot.com
- Organization: MOTOROLA
- Date: Tue, 2 Apr 1996 15:15:45 GMT
- Message-ID: <1996Apr2.151545.28720@schbbs.mot.com>
- References: <MARKT.96Apr1200203@atlas.harlqn.co.uk>
- Sender: news@schbbs.mot.com (SCHBBS News Account)
- Nntp-Posting-Host: 129.188.128.126
-
- In article <MARKT.96Apr1200203@atlas.harlqn.co.uk> markt@harlqn.co.uk (Mark
- Tillotson) writes:
- > shang@corp.mot.com (David L. Shang) wrote:
- > >
- > > The more a program depends on GC, the more likely it will exhaust memory;
- > > because the storage is collected only when all its references are
- > > no longer valid, not at the time when all its references are no longer
- > > used.
- > In complex software this is not true... explicit management of
- > storage places such a burden on the programmer that either security is
- > compromised (catastrophic bugs) or space leaks occur (that a GC would
- > easily have caught).
-
- I did not mention that explicit management of storage is better.
- On the contrary, it should be avoided unless it is absolutely
- necessary. However, GC is not always better in terms of efficiency
- and memory economy, compared to by-value variables. By-value variables
- are not explicit. They cannot be be allocated/deallocated explicitly.
- The management of storage is done usually by the compiler, linker,
- loader, or the run-time system.
-
- > In a GC-based system you only have to debug the
- > GC, not every single program that calls free() !!
- >
-
- No really true. You still have the risk of dangling resources,
- invalid references, unless you prohibit the program to process
- resources such as files, persistent objects, and network resources.
-
- > > Be careful, never make a variable's lifetime unecessarily longer
- > > than the required.
- > This advice for avoiding space leaks happens to be valid _whether or
- > not_ automatic GC is in operation!
- >
- Using automatic GC is helpful, but not a complete solution to
- all kinds of resources.
-
- > > With Java's array, memory will be smashed into millions of small
- > > pieces. Here is a brief comparison:
- >
- > <array of struct of 3 floats example omitted>
- >
- > On many machines one load instruction is cheaper than multiplying an
- > index by 3, so Java's approach is actually faster.
-
- How? Note that Java's array element must contain two references: one
- to the type of the element and another to the object. Therefore,
- multiplying an index by 8 must be performed first then adding an shift
- (4) for locating the object reference, and then a load instruction
- can be performed. If it is a two or three dimension array, such procedure
- must be done two are three times.
-
- > equal)... Object allocation rarely costs a significant proportion of
- > execution time, unless the application fails to do anything useful
- > with what it allocates!!
-
- One or two object allocations cost nothing, I agree. But millions of
- millions will do!
-
- Performance is not the only issue. Another problem is
- the object transfer from one address space to another, for example,
- from one computer to another on the network, or from memory to disk.
- If smart reference is the only choice for object, there is no easy
- way to do things like network programming.
-
- I am not saying that GC is bad. It is good, but it is not enough.
- Therefore, it should not be the only choice.
-
- I am not saying that C++ pointers are good It is bad, but sometimes
- you have to use them for the sake of others not using them (e.g., to
- implement smart references).
-
- By-value variables (or static references) are not C++ pointers. They
- are equally safe as smart references. They are required not just for
- performance, but for object transfer from one address space to a
- different address space.
-
- There many many other kinds of object references that GC can not
- handle, for example, netword reference, references to clones,
- persistent object reference, etc. Without them, processing resources
- can never be safe.
-
- David Shang
-
-
-